package com.example.foobar.dao.service.impl;

import com.example.foobar.dao.service.DaConfigDaoService;
import com.example.foobar.entity.DaConfig;
import com.example.foobar.mapper.DaConfigMapper;
import com.example.foobar.param.DaConfigPageParam;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.transaction.annotation.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 分析系统配置文件 服务实现类
 *
 * @author 郑英奔
 * @since 2021-05-31
 */
@Slf4j
@Service
public class DaConfigDaoServiceImpl extends BaseServiceImpl<DaConfigMapper, DaConfig> implements DaConfigDaoService {

    @Autowired
    private DaConfigMapper daConfigMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean saveDaConfig(DaConfig daConfig) throws Exception {
        return super.save(daConfig);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean updateDaConfig(DaConfig daConfig) throws Exception {
        return super.updateById(daConfig);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean deleteDaConfig(Long id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public Paging<DaConfig> getDaConfigPageList(DaConfigPageParam daConfigPageParam) throws Exception {
        Page<DaConfig> page = new PageInfo<>(daConfigPageParam, OrderItem.desc(getLambdaColumn(DaConfig::getCreateTime)));
        LambdaQueryWrapper<DaConfig> wrapper = new LambdaQueryWrapper<>();
        IPage<DaConfig> iPage = daConfigMapper.selectPage(page, wrapper);
        return new Paging<DaConfig>(iPage);
    }

}
